package com.atguigu.jdbctemplate;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * Title: UserDao
 * Description: TODO
 *
 * @author gejx
 * @version V1.0
 * @date 2021-12-07
 */
@Component
@Transactional()//声明事务
public class UserDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void test(){
        String sql ="insert user values(?,?,?,?,?)";
        System.out.println(jdbcTemplate.update(sql, null, "李四", 18, "1255@sqq", 2));
    }
    public void update(){
        String sql ="update user set  age=(age-?) WHERE id=?;";
        String sql1 ="update user set  age=(age+?) WHERE id=?;";
        jdbcTemplate.update(sql,1,1);
//        int a=1/0;
        jdbcTemplate.update(sql1,1,2);
    }
}
